package com.wondertek.liveroom;

import java.util.ArrayList;
import java.util.List;

import com.jasontools.data.VideoChannelPc;
import com.jasontools.http.HttpAjaxUrl;
import com.jasontools.http.HttpManager;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyVideoIndexListViewAdapter extends BaseAdapter {

	private Context context = null;
	private LayoutInflater inflater = null;
	private List<VideoChannelPc> listData = null;
	
	public MyVideoIndexListViewAdapter(Context context, List<VideoChannelPc> list) {
		this.context = context;
		this.listData = list;
		this.inflater = LayoutInflater.from(context);
	}
	
	public void setData(List<VideoChannelPc> list) {
		this.listData = list;
	}

	@Override
	public int getCount() {
		return listData.size();
	}

	@Override
	public Object getItem(int position) {
		return listData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		VideoChannelPc video = listData.get(position);
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_video_listview, null);
			holder = new ViewHolder();
			holder.ivIcon = (ImageView) convertView.findViewById(R.id.iv_item_video_listview_icon);
			holder.tvName = (TextView) convertView.findViewById(R.id.tv_item_video_listview_name);
			holder.tvDesc = (TextView) convertView.findViewById(R.id.tv_item_video_listview_desc);
			holder.tvSubscriberCount = (TextView) convertView.findViewById(R.id.tv_item_video_listview_subscriber_count);
			holder.tvLookerCount = (TextView) convertView.findViewById(R.id.tv_item_video_listview_looker_count);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.tvName.setText(video.getRecordName());
		holder.tvDesc.setText(video.getOwner() + "       " + video.getCateName());
		holder.tvLookerCount.setText(String.valueOf(video.getRecordVisitor()));
		HttpManager.getFB(context).display(holder.ivIcon, HttpAjaxUrl.getServerUrl(HttpAjaxUrl.URL_LIVE_BG));
		
		return convertView;
	}
	
	
	private class ViewHolder {
		public ImageView ivIcon;
		public TextView tvName;
		public TextView tvDesc;
		public TextView tvSubscriberCount;
		public TextView tvLookerCount;
	}

}
